<?php echo $html->css(array('datepicker')); ?>
<?php echo $javascript->link(array('jquery-1.4.2', 'jquery.jeditable', 'javaEdit', 'datepicker')); ?>
<script type="text/javascript">
$(document).ready(function(){
	// toggle the search form
	$('.search-toggle').click(function(){
		$('#SearchForm').toggle();
	});
	$('#SearchForm').hide();
});
</script>

<div class="Timesheets index">

<fieldset>
	<legend>Staff Timesheets - <?php echo $time->format($format = 'd-m-Y', $this->passedArgs['Timesheet.startDate']) ?> to <?php echo $time->format($format = 'd-m-Y', $this->passedArgs['Timesheet.endDate']) ?></legend><br/>
<center><?php echo $html->link(__('Search', true), 'javascript:void(0)', array('class'=>'search-toggle')); ?></center>
<?php echo $form->create('Timesheet',array('action'=>'search', 'id'=>'SearchForm'));?>
	<fieldset class="search">
 		<legend><?php __('Search');?></legend>
	<?php
		echo '<center><b>'; 
		e($form->label('startDate', 'Start Date')); 		
		e($form->day('startDate', date('d'), array('id' => 'ssd-dd'), false)." - ");
		e($form->month('startDate', date('m'), array('id' => 'ssd-mm'), false)." - ");
		e($form->year('startDate', '1900', date('Y') + 50, date('Y'), array('id' => 'ssd', 'class' => 'show-weeks dateformat-d-ds-m-ds-Y statusformat-l-cc-sp-d-sp-F-sp-Y highlight-days-67 split-date opacity-90'), false));
		echo "<br />";
		echo "<br />";		
		e($form->label('endDate', 'End Date'));
		echo '</b>'; 		
		e($form->day('endDate', date('d'), array('id' => 'eed-dd'), false)." - ");
		e($form->month('endDate', date('m'), array('id' => 'eed-mm'), false)." - ");
		e($form->year('endDate', '1900', date('Y') + 50, date('Y'), array('id' => 'eed', 'class' => 'show-weeks dateformat-d-ds-m-ds-Y statusformat-l-cc-sp-d-sp-F-sp-Y highlight-days-67 split-date opacity-90'), false));
		echo '<br />';
		echo '<br />';	
		echo $form->submit('Search');
		echo '</center>';
	?>
	</fieldset>
<?php echo $form->end();?>
<br /><br />
	

	<?php echo $form->create('Timesheet',array('id'=>'PostListForm','url'=>array('controller'=>'timesheets','action'=>'multi')));?>
	<?php
		echo '<center>';
		echo $paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
		echo '&nbsp;&nbsp;';
		echo $paginator->numbers();
		echo '&nbsp;&nbsp;';
		echo $paginator->next('Next >>', null, null, array('class' => 'disabled'));
		echo '</center><br />';
	?> 
	<?php if(!empty($timesheets)): ?>
			<table cellpadding="0" cellspacing="0">
	<tr>
			<th class="title"><?php echo $this->Paginator->sort('client_id');?></th>
			<th class="title"><?php echo $this->Paginator->sort('user_id');?></th>
			<th class="title"><?php echo $this->Paginator->sort('date');?></th>
			<th class="title"><?php echo $this->Paginator->sort('Customer','customer name');?></th>
			<th class="title"><?php echo $this->Paginator->sort('type');?></th>
			<th class="title"><?php echo $this->Paginator->sort('location');?></th>
			<th class="title"><?php echo $this->Paginator->sort('Start', 'start time');?></th>
			<th class="title"><?php echo $this->Paginator->sort('Finish', 'finish time');?></th>
			<th class="title"><?php echo $this->Paginator->sort('Services', 'services provided');?></th>
			<th class="title"><?php echo $this->Paginator->sort('Resources','hardware and software');?></th>
			<th class="actions"><?php __('Actions');?></th>
	</tr>
	<?php
	$i = 0;
	foreach ($timesheets as $timesheet):
		$class = null;
		if ($i++ % 2 == 0) {
			$class = ' class="altrow"';
		}
	?>
	<tr<?php echo $class;?>>
		<td>
			<?php echo $this->Html->link($timesheet['Client']['name'], array('controller' => 'clients', 'action' => 'view', $timesheet['Client']['id'])); ?>
		</td>
		<td>
			<?php echo $this->Html->link($timesheet['User']['username'], array('controller' => 'users', 'action' => 'view', $timesheet['User']['id'])); ?>
		</td>
		<td><?php echo $timesheet['Timesheet']['date']; ?>&nbsp;</td>
		<td><?php echo $timesheet['Timesheet']['customer name']; ?>&nbsp;</td>
		<td><?php echo $timesheet['Timesheet']['type']; ?>&nbsp;</td>
		<td><?php echo $timesheet['Timesheet']['location']; ?>&nbsp;</td>
		<td><?php echo $timesheet['Timesheet']['start time']; ?>&nbsp;</td>
		<td><?php echo $timesheet['Timesheet']['finish time']; ?>&nbsp;</td>
		<td><?php echo $timesheet['Timesheet']['services provided']; ?>&nbsp;</td>
		<td><?php echo $timesheet['Timesheet']['hardware and software']; ?>&nbsp;</td>
		<td class="actions">
			<?php echo $this->Html->link(__('View', true), array('action' => 'view', $timesheet['Timesheet']['id'])); ?>
			<?php echo $this->Html->link(__('Edit', true), array('action' => 'edit', $timesheet['Timesheet']['id'])); ?>
			<?php echo $this->Html->link(__('Delete', true), array('action' => 'delete', $timesheet['Timesheet']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $timesheet['Timesheet']['id'])); ?>
		</td>
	</tr>
<?php endforeach; ?>
	</table>
		<?php
			echo '<center>';
			echo $paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
			echo '&nbsp;&nbsp;';
			echo $paginator->numbers();
			echo '&nbsp;&nbsp;';
			echo $paginator->next('Next >>', null, null, array('class' => 'disabled'));
			echo '<br /><br />';
			echo $paginator->counter(array('format' => 'Page %page% of %pages%, showing %current% records out of %count% total.')); 
			echo '</center><br /><br />';
		?>		
		<center> 
		<?php 
	
			$all = $this->webroot . 'timesheets/';
			echo $form->button('List All Timesheets', array('type'=>'button', 'onClick' => "location.href='".$all."'"));
		?>
		</center>
	<?php
		else:
			echo '<center>';
			echo 'No Timesheets<br /><br />';
			$all = $this->webroot . 'timesheets/';
			echo $form->button('List All Timesheets', array('type'=>'button', 'onClick' => "location.href='".$all."'"));
			echo '</center>';
		endif;
	?>	
</fieldset>
</div>
